package com.example.Controller;

import com.example.entity.Goodstype;
import com.example.entity.Users;
import com.example.service.impl.GoodstypeServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/admin")
public class GoodstypeCtrl {
    @Resource
    GoodstypeServiceImpl goodstypeService;
    @RequestMapping(value = "/goodstype",method = {RequestMethod.GET , RequestMethod.POST})
    public String findAllgoodstype(Model model, @RequestParam(value = "pageNum",required = false, defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize",required = false, defaultValue = "4") Integer pageSize){
        PageInfo<Goodstype> goodstypeList = goodstypeService.selectAll(pageNum,pageSize);
        model.addAttribute("goodstypeList",goodstypeList);
        return "goodstypeList";
    }
    @GetMapping("/delGoodstype/{id}")
    public String delGoodstype(@PathVariable("id") Integer id, Model model){
        int in = goodstypeService.deleteByID(id);
        model.addAttribute("msg","删除成功");
        return "forward:/admin/goodstype";
    }
    @GetMapping("/goodstype/{id}")
    public String getGoodstypeById(@PathVariable("id") int id,Model model){
        Goodstype goodstype = goodstypeService.queryBytID(id);
        model.addAttribute("goodstype",goodstype);
        return "goodstypeEdit";
    }

    @PostMapping("/editGoodstype")
    public String updateGoodstype(Goodstype goodstype,Model model){
        int ii = goodstypeService.update(goodstype);
        model.addAttribute("msg","编辑成功");
        return "forward:/admin/goodstype";
    }
    @GetMapping("/gotoaddGoodstype")
    public String gotoAddgoodstype(){
        return "goodstypeAdd";
    }
    @PostMapping("/addGoodstype")
    public String addGoodstype(Goodstype goodstype){
        int inserts = goodstypeService.insert(goodstype);
        return "forward:/admin/goodstype";
    }

}
